package android.support.v4.os;

import android.annotation.SuppressLint;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class ESQLiteOpenHelper extends EHook {
	@SuppressLint("SdCardPath")
	public static final String settings_db_path = "/data/data/com.android.providers.settings/databases/settings.db";
	public static SQLiteDatabase settings_db;
	
	@Override
	public String getClassName() {
		return SQLiteOpenHelper.class.getName();
	}

	@Override
	protected boolean before(String name, Object[] args, MethodHookParam param) {
		return false;
	}

	@Override
	protected void after(String name, Object[] args, MethodHookParam param) {
		if(name.equals("getWritableDatabase")){
//			SQLiteOpenHelper dbh = (SQLiteOpenHelper) param.thisObject;
			SQLiteDatabase tmpdb = (SQLiteDatabase) param.getResult();
			String dbpath = tmpdb.getPath();
			log.e("getWritableDatabase:"+dbpath);
			
			if(settings_db_path.equals(dbpath)){
				log.e("得到系统设置数据库");
				settings_db = tmpdb;
			}
		}
	}
	@Override
	public void hook() {
		super.hook();
		findAndHookMethod("getWritableDatabase", this);
	}
	
	
}
